/**  
 * 文 件 名: LoginFilter.java  
 * 描    述：   
 * 版    权：Copyright (c)20010-2012 taiji All Rights Reserved.
 * 公    司: 太极软件 
 * 作    者：彭定雄                     
 * 版    本: 1.0  
 * 创建时间: Aug 6, 2012
 *  
 * 修改历史：  
 * 时间                             作者                       版本                        描述  
 * ------------------------------------------------------------------  
 * Aug 6, 2012        彭定雄                1.0          1.0 Version  
 */

/**
 * 
 */
package com.tongzhou.filter;

import java.io.IOException;
import java.util.Map;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.opensymphony.xwork2.ActionContext;

public class LoginFilter implements Filter {
	public void destroy() {
	}

	public void doFilter(ServletRequest req, ServletResponse res,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) req;
		HttpServletResponse response = (HttpServletResponse) res;
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");

		String url = request.getServletPath();
		String path = request.getContextPath();
		if(url.contains("checkUser.action")||url.contains("inlogin.action")){
			chain.doFilter(request, response);
			return;
		}
		HttpServletRequest httpRequest = (HttpServletRequest)request;
		HttpSession session = httpRequest.getSession();
		String id=(String) session.getAttribute("id");
		
		if (id != null&&!id.equals("")) {
			chain.doFilter(request, response);
		}else{		
			response.sendRedirect("/TongZhou/index.jsp");
		}
		
	}

	public void init(FilterConfig filterConfig) throws ServletException {
	}
}
